﻿namespace Bildverarbeitung.CGFilter
{
    using System;
    using System.Drawing;
    using Bildverarbeitung;
    using AForge.Imaging.Filters;
    using AForge.Imaging;

    public class MatthiasKraftFilter : Bildverarbeitung.IFilter
    {
        public Bitmap GetSummerizedDifferencefromAverage(Bitmap[] images)
        {
            Bitmap imageArray = new Bitmap(images[0].Width, images[0].Height);
            Bitmap newpicture = images[0]; ;

            for (int i = 0; i < images.Length - 2; i++)
            {
                ThresholdedDifference filter = new ThresholdedDifference(50);
                filter.OverlayImage = newpicture;
                imageArray = filter.Apply(images[i + 1]);

                AForge.Imaging.BlobCounter blobCounter = new BlobCounter(imageArray);
                Rectangle[] rects = blobCounter.GetObjectsRectangles();

                Graphics g = Graphics.FromImage(newpicture);
                TextureBrush textureBrush = new TextureBrush(images[i + 2]);
                g.FillRectangles(textureBrush, rects);
            }
            return newpicture;
        }

        public String GetName()
        {
            return ("KraftMatthias");
        }
    }
}
